package edu.dayu.controller;

import com.github.pagehelper.PageInfo;
import edu.dayu.pojo.*;
import edu.dayu.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/api")
public class ApiController {

    @Autowired
    private ActivityService activityService;
    @Autowired
    private ImageService imageService;
    @Autowired
    private ActivityTypeService activityTypeService;
    @Autowired
    private ClubService clubService;
    @Autowired
    private ArticleService articleService;
    @Autowired
    private ArticleTypeService articleTypeService;
    @Autowired
    private ClubTypeService clubTypeService;
    @Autowired
    private ApplicantService applicantService;


    @PostMapping("/applicantInsert")
    public boolean applicantInsert (Applicant applicant){
        return applicantService.applicantInsert(applicant);
    }

    @PostMapping("/clubTypeList")
    public List<ClubType> clubTypeList(ClubType clubType){
        return clubTypeService.clubTypeList(clubType);
    }

    @PostMapping("/articleTypeList")
    public List<ArticleType> articleTypeList (ArticleType articleType){
        return  articleTypeService.articleTypeList(articleType);
    }
    @PostMapping("/articleById")
    public Article articleById(Article article){
        List<Article> articleList = articleService.articleList(article).getList();
        Article article1 = new Article();
        for (Article article2 : articleList) {
            article1 = article2;
        }
        return article1;
    }

    @PostMapping("/articleList")
    public PageInfo<Article> articleList(Article article){
        return articleService.articleList(article);
    }

    @PostMapping("/clubByName")
    Club clubByName(String name){
        return clubService.clubByName(name);
    }

    @PostMapping("/clubList")
    public PageInfo<Club> clubList(Club club){
        return clubService.clubList(club);
    }

    @PostMapping("/clubById")
    public Club clubById(Club club){
        PageInfo<Club> clubPageInfo = clubService.clubList(club);
        List<Club> list = clubPageInfo.getList();
        Club club1 = new Club();
        for (Club club2 : list) {
            club1 = club2;
        }
        return club1;
    }

    @PostMapping("/activityTypeList")
    public List<ActivityType> activityTypeList (ActivityType articleType){
        return  activityTypeService.activityTypeList(articleType);
    }

    @PostMapping("/activityList")
    public PageInfo<Activity> activityList(Activity activity){
        return activityService.activityList(activity);
    }

    @PostMapping("/activityById")
    public Activity activityById(Activity activity){
        List<Activity> activityList = activityService.activityList(activity).getList();
        Activity activity1 = new Activity();
        for (Activity activity2 : activityList) {
            activity1 = activity2;
        }
        return activity1;
    }

    @PostMapping("/ImageList")
    public PageInfo<Image> ImageList(Image image){
        return imageService.ImageList(image);
    }
}
